package demo2.util;

import demo2.util.ai.RandomSearcher;

public class RandomGameHandler implements GameHandler {

    private GameHandler nextHandler;

    @Override
    public void handleRequest() {

        if (!solve() && nextHandler != null) {
            nextHandler.handleRequest();
        }

    }

    @Override
    public void setNextHandler(GameHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public boolean solve() {

        Game.getInstance().setSolution(new RandomSearcher().searchAll(new int[]{Game.getInstance().getDigitAt(0),
                Game.getInstance().getDigitAt(1),
                Game.getInstance().getDigitAt(2),
                Game.getInstance().getDigitAt(3),


        }));
        return Game.getInstance().getSolution().isEmpty();
    }


}